package com.ss.android.article.base.feature.detail2.widget;

import android.content.Context;
import android.net.Uri;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.RoundingParams;
import com.ss.android.article.base.feature.update.a.UserInfo;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;

import java.util.List;

public final class LikeAndRewardsLayout extends RelativeLayout {
    public TextView a;
    public TextView b;
    public com.ss.android.article.base.ui.DiggLayout mDiggLayout;
    public View d;
    public View e;
    public LinearLayout f;
    public TextView g;
    public int h;
    private int mAdmireNum;

    public LikeAndRewardsLayout(Context context) {
        super(context);
        LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.cw, ((ViewGroup) this));
        this.a = this.findViewById(com.ss.android.article.browser.R.id.s3);
        this.b = this.findViewById(com.ss.android.article.browser.R.id.s5);
        this.mDiggLayout = this.findViewById(com.ss.android.article.browser.R.id.s4);
        this.mDiggLayout.setTextColor$255f295(com.ss.android.article.browser.R.color.yo);
        com.ss.android.article.base.ui.DiggLayout v0 = this.mDiggLayout;
        v0.b = com.ss.android.j.b.isNightModeToggled();
        v0.mAnimationImageView.a(com.ss.android.article.browser.R.drawable.oc, R.drawable.ob, v0.b);
        v0.invalidate();
        this.d = this.findViewById(com.ss.android.article.browser.R.id.divider);
        this.e = this.findViewById(com.ss.android.article.browser.R.id.s6);
        this.f = this.findViewById(com.ss.android.article.browser.R.id.s7);
        this.g = this.findViewById(com.ss.android.article.browser.R.id.s8);
        this.a.setOnTouchListener(new View.OnTouchListener() {

            public final boolean onTouch(View arg3, MotionEvent arg4) {
                switch (arg4.getAction()) {
                    case 0: {
                        if (LikeAndRewardsLayout.this.a == null) {
                            return false;
                        }

                        LikeAndRewardsLayout.this.a.setAlpha(0.5f);
                        break;
                    }
                    case 1:
                    case 3: {
                        if (LikeAndRewardsLayout.this.a == null) {
                            return false;
                        }

                        LikeAndRewardsLayout.this.a.setAlpha(1f);
                        break;
                    }
                }

                return false;
            }
        });
    }

    public final View a(UserInfo arg5) {
        int v1 = 0;
        View v2 = LayoutInflater.from(this.getContext()).inflate(com.ss.android.article.browser.R.layout.hx, this.f, false);
        ((NightModeAsyncImageView) v2.findViewById(com.ss.android.article.browser.R.id.avatar)).setUrl(arg5.avatarUrl);
        View v0 = v2.findViewById(com.ss.android.article.browser.R.id.mark_v);
        if (!arg5.userVerified) {
            v1 = 4;
        }

        ((ImageView) v0).setVisibility(v1);
        return v2;
    }

    public final int getAdmireNum() {
        return this.mAdmireNum;
    }

    public final int getAvatarCount() {
        return this.h;
    }

    public final void setAdmireButtonVisible(boolean arg4) {
        int v2 = 8;
        if (arg4) {
            if (this.a.getVisibility() != VISIBLE) {
                this.a.setVisibility(VISIBLE);
                this.d.setVisibility(VISIBLE);
            }
        } else if (this.a.getVisibility() == VISIBLE) {
            this.a.setVisibility(GONE);
            this.d.setVisibility(GONE);
        }
    }

    public final void setAdmireNum(int admireNum) {
        this.mAdmireNum = admireNum;
        this.g.setText(this.getResources().getString(com.ss.android.article.browser.R.string.detail_admire_count, new Object[]{Integer.valueOf(admireNum)}));
    }

    public final void setAdmireUserAvatars(List arg10) {
        this.h = arg10.size();
        if (this.h > 0) {
            if (this.e.getVisibility() != VISIBLE) {
                this.e.setVisibility(VISIBLE);
            }

            for (int i = 0; i < arg10.size(); ++i) {
                LinearLayout v3 = this.f;
                Object v0 = arg10.get(i);
                NightModeAsyncImageView nightModeAsyncImageView = new NightModeAsyncImageView(this.getContext());
                RoundingParams roundingParams = new RoundingParams();
                roundingParams.mRoundAsCircle = true;
                int v6 = ((int) UIUtils.dp2px(this.getContext(), 1f));
                roundingParams.setBorder(this.getResources().getColor(com.ss.android.article.browser.R.color.b1), ((float) v6));
                ((GenericDraweeHierarchy) nightModeAsyncImageView.getHierarchy()).setRoundingParams(roundingParams);
                nightModeAsyncImageView.setPlaceHolderImage(com.ss.android.article.browser.R.drawable.big_defaulthead_head);
                nightModeAsyncImageView.setImageURI(((Uri) v0));
                int v0_1 = ((int) TypedValue.applyDimension(1, 4f, this.getResources().getDisplayMetrics()));
                int v1 = this.getResources().getDimensionPixelSize(R.dimen.c2) + v6;
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(v1, v1);
                if (i > 0) {
                    layoutParams.leftMargin = -v0_1;
                }

                nightModeAsyncImageView.setLayoutParams(((ViewGroup.LayoutParams) layoutParams));
                v3.addView(((View) nightModeAsyncImageView));
            }
        } else {
            if (this.e.getVisibility() != VISIBLE) {
                return;
            }
            this.e.setVisibility(GONE);
        }
    }

    public final void setDiggAnimationView(com.ss.android.article.base.ui.DiggAnimationView diggAnimationView) {
        if (diggAnimationView != null && this.mDiggLayout != null) {
            this.mDiggLayout.setDiggAnimationView(diggAnimationView);
        }
    }

    public final void setLikeNum(int likeNum) {
        if (likeNum <= 0) {
            this.mDiggLayout.setText(com.ss.android.article.browser.R.string.detail_digg);
        } else {
            this.mDiggLayout.setText(String.valueOf(likeNum));
        }
    }

    public final void setLiked(boolean arg2) {
        this.mDiggLayout.setSelected(arg2);
    }

    public final void setOnAdmireClickListener(View.OnClickListener arg2) {
        this.a.setOnClickListener(arg2);
    }

    public final void setOnAvatarClickListener(View.OnClickListener arg2) {
        this.e.setOnClickListener(arg2);
    }

    public final void setOnLikeClickListener(View.OnClickListener arg2) {
        this.mDiggLayout.setOnClickListener(arg2);
    }

    public final void setOnReportClickListener(View.OnClickListener arg2) {
        this.b.setOnClickListener(arg2);
    }

    public final void setRewardUserAvatars(List arg4) {
        this.h = arg4.size();
        if (this.h > 0) {
            if (this.e.getVisibility() != VISIBLE) {
                this.e.setVisibility(VISIBLE);
            }

            int v1;
            for (v1 = 0; v1 < arg4.size(); ++v1) {
                Object v0 = arg4.get(v1);
                if (v0 != null) {
                    this.f.addView(this.a(((UserInfo) v0)));
                }
            }
        } else {
            if (this.e.getVisibility() != VISIBLE) {
                return;
            }

            this.e.setVisibility(GONE);
        }
    }
}

